<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Insert title here</title>

<%@ include file="static_res.jsp"%>

<style type="text/css">
.bottom0 {
	margin-bottom: 0px;
}
.themeColor{
	font-weight: bold;
	font-size:22px;
	color:#EE6E87;
}
.bold{
	font-weight: bold;
}
</style>
<script>

    function getJoinInfo()
	{
	    var uid = "${sessionScope.user.id}";
        var param = "uid="+uid;
        $.ajax({
            type : "POST",
            url : "<%=path%>/act/joinInfo",
            data : param,
            dateType : "json",
            success : function(result) {
                var list = result;

                $.each( JSON.parse(list), function(index, content){
                    $('#joinIn'+content).addClass("disabled");
                });
            }


        });
	}
	$(function() {
		var name = "${sessionScope.user.name}";

		if (name == null || name == "")
			$('#self').text('还未登录，请登录');
		else
			$('#self').text(name);

        $("a[id^='joinIn']").click(function(){
            var str = ($(this).attr('id'));
            num = parseInt(str.replace(/[^0-9]/ig,""));
			var act_uid = $('#hidevalueuid'+num).val();
			var act_title = $('#hidevaluetitle'+num).val();


            var param = "actId="+num+"&actUid="+act_uid+"&actTitle="+act_title;
            $.ajax({
                type : "POST",
                url : "<%=path%>/act/join",
                data : param,
                dateType : "text",
                success : function(result) {
                    if ("0" == result)
                        Materialize.toast('加入失败 ！', 3000);
                    else if ("1" == result) {
                        Materialize.toast('加入成功 ！', 3000);

                    }

                }
            });

            var cur = $('#cur'+num).html();
            cur = parseInt(cur)+1;
            $('#cur'+num).html(cur);
            $(this).addClass("disabled");
        });
	});
</script>
</head>

<body onload="getJoinInfo()">
	<div class="row bottom0">
		<%@ include file="header.jsp"%>
	</div>

	<div class="container">
		<%--3,9布局--%>
		<div class="row">
			<div class="col s3">
				<div class="row"></div>
				<c:forEach items="${ActShow}" var="act">
					<div class="card horizontal hoverable z-depth-4">
						<div class="card-stacked">
							<div class="card-content">
								<p class="flow-text">${act.title}</p>
								创建人:<a href="<%=path%>/user/visitUser?aid=${act.uid}"><span class="bold">${act.createPerson}</span></a> |
									当前人数:<span id="cur${act.id}" class="bold">${act.currentCount}</span> |
									最大人数:<span class="bold">${act.maxCount}</span></p>
								<p>${act.content}</p>
								<c:choose>

									<c:when test="${act.leftDay > 0}">
										剩余<span class="themeColor">${act.leftDay}</span>天截止
									</c:when>
									<c:otherwise>
										<span class="themeColor">活动已过期</span>
									</c:otherwise>
								</c:choose>

								<input id="hidevalueuid${act.id}" type="hidden" value="${act.uid}"/>
								<input id="hidevaluetitle${act.id}" type="hidden" value="${act.title}"/>
							</div>
							<c:choose>
								<c:when test="${act.leftDay < 0 or act.currentCount >= act.maxCount}">

									<div class="card-action">
										<a id="joinIn${act.id}" class="right waves-effect disabled waves-light btn">加入</a>
									</div>
								</c:when>
								<c:otherwise>
									<div class="card-action">
										<a id="joinIn${act.id}" class="right waves-effect waves-light btn">加入</a>
									</div>
								</c:otherwise>
							</c:choose>


						</div>
					</div>
				</c:forEach>
				<a href="<%=path%>/act/allActivitys">查看更多</a>
			</div>



			<%--9 start--%>
			<div class="col s9">

				<div class="row"></div>

				<ul class="collection">
					<c:forEach items="${artlist}" var="art">
					<li class="collection-item avatar">
						<img src="<%=ipath%>${art.avatar}" alt="" class="circle">
						<a href="<%=path%>/article/getArticle?aid=${art.id}" class="title">${art.title}</a>
						<p>
							<a href="<%=path%>/user/visitUser?uid=${art.uid}">${art.name}</a> <br>
							${art.abst}
						</p>
						<a href="#!" class="secondary-content"><i class="material-icons">grade</i></a>
					</li>
					</c:forEach>
				</ul>
				<a href="<%=path%>/article/allArticles">查看更多</a>



			</div> <%--9 end--%>
		</div><%--3,9 row end--%>
	</div>

	</div>

</body>

</html>